package demosms;

import java.util.HashMap;
import java.util.Set;

import org.junit.Test;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

public class SmsTest {
	@Test
	public void testSms() {
//		HashMap<String, Object> result = null;
//
//		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
//		restAPI.init("app.cloopen.com", "8883");// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
//		restAPI.setAccount("8aaf070870e20ea1017152c44e553778", "a5386ab37ec5462db1c2f4ba02455351");// 初始化主帐号和主帐号TOKEN
//		restAPI.setAppId("8aaf070870e20ea1017152c44eba377f");// 初始化应用ID
//		result = restAPI.sendTemplateSMS("15886595137","1" ,new String[]{"1234","5"});
//
//		System.out.println("SDKTestSendTemplateSMS result=" + result);
//		
//		if("000000".equals(result.get("statusCode"))){
//			//正常返回输出data包体信息（map）
//			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
//			Set<String> keySet = data.keySet();
//			for(String key:keySet){
//				Object object = data.get(key);
//				System.out.println(key +" = "+object);
//			}
//		}else{
//			//异常返回输出错误码和错误信息
//			System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
//		}
		
		//生产环境请求地址：app.cloopen.com
		String serverIp = "app.cloopen.com";
	    //请求端口
	    String serverPort = "8883";
	    //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
	    String accountSId = "8aaf070870e20ea1017152c44e553778";
	    String accountToken = "a5386ab37ec5462db1c2f4ba02455351";
	    //请使用管理控制台中已创建应用的APPID
	    String appId = "8aaf070870e20ea1017152c44eba377f";
	    CCPRestSmsSDK sdk = new CCPRestSmsSDK();
	    sdk.init(serverIp, serverPort);
	    sdk.setAccount(accountSId, accountToken);
	    sdk.setAppId(appId);
	    sdk.setBodyType(BodyType.Type_JSON);
	    String to = "15886595137";
	    String templateId= "1";
	    String[] datas = {"1234","5"};
	    HashMap<String, Object> result = sdk.sendTemplateSMS(to,templateId,datas);
	    if("000000".equals(result.get("statusCode"))){
	        //正常返回输出data包体信息（map）
	        HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
	        Set<String> keySet = data.keySet();
	        for(String key:keySet){
	            Object object = data.get(key);
	            System.out.println(key +" = "+object);
	        }
	    }else{
	        //异常返回输出错误码和错误信息
	        System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
	    }
	}
}
